package com.zygh.policeasset.controller;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.util.StringUtil;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.component.ProjectCode;
import com.zygh.policeasset.pojo.ProcessRecord;
import com.zygh.policeasset.service.ProcessRecordSerivce;
import com.zygh.policeasset.service.ProjectApprovalStepsService;
import com.zygh.policeasset.service.ProjectNoService;
import com.zygh.policeasset.service.ProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/processrecord"})
@Api(tags = {"审批流程"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/ProcessRecordController.class */
public class ProcessRecordController {
    @Autowired
    ProcessRecordSerivce processRecordSerivce;
    @Autowired
    ProjectService projectService;
    @Autowired
    ProjectNoService projectNoService;
    @Autowired
    ProjectCode projectCode;
    @Autowired
    ProjectApprovalStepsService projectApprovalStepsService;

    @RequestMapping(value = {"/add"}, method = {RequestMethod.POST})
    @ApiOperation("添加审批")
    public Object add(@RequestBody ProcessRecord processRecord) {
        if (StringUtil.isEmpty(String.valueOf(processRecord.getProjectId()))) {
            return new CommonResult().validateFailed("项目id不能为空");
        }
        if (StringUtil.isEmpty(processRecord.getProcessName())) {
            return new CommonResult().validateFailed("流程不能为空");
        }
        processRecord.setProcessTime(DateUtil.now());
        if (this.processRecordSerivce.add(processRecord).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    @RequestMapping(value = {"/findAll"}, method = {RequestMethod.GET})
    @ApiImplicitParam(name = "projectId", value = "项目编号", required = true, paramType = "query")
    @ApiOperation("按项目编码查询")
    public Object findAllByProjectId(int projectId) {
        if (StringUtil.isEmpty(String.valueOf(projectId))) {
            return new CommonResult().validateFailed("项目编号为空");
        }
        return new CommonResult().success(this.processRecordSerivce.findAll(projectId));
    }

    @RequestMapping(value = {"/findByProjectId"}, method = {RequestMethod.GET})
    @ApiOperation("按主键ID和项目类型查询")
    public Object findByProjectId(@RequestParam("projectId") Integer projectId, @RequestParam("processName") String processName) {
        if (StringUtil.isEmpty(String.valueOf(projectId))) {
            return new CommonResult().validateFailed("项目编号为空");
        }
        return new CommonResult().success(this.processRecordSerivce.findByProjectId(projectId, processName));
    }

    @RequestMapping(value = {"/submit"}, method = {RequestMethod.POST})
    @ApiOperation("上级项目提交")
    public Object submit(@RequestBody ProcessRecord processRecord) {
        if (StringUtil.isEmpty(String.valueOf(processRecord.getProjectId()))) {
            return new CommonResult().validateFailed("项目id不能为空");
        }
        if (StringUtil.isEmpty(processRecord.getProcessName())) {
            return new CommonResult().validateFailed("流程类型不能为空");
        }
        if (this.processRecordSerivce.submit(processRecord).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("提交失败");
    }

    @RequestMapping(value = {"/submitbenji"}, method = {RequestMethod.POST})
    @ApiOperation("本级项目提交")
    public Object submitbenji(@RequestBody ProcessRecord processRecord) {
        if (StringUtil.isEmpty(String.valueOf(processRecord.getProjectId()))) {
            return new CommonResult().validateFailed("项目id不能为空");
        }
        if (StringUtil.isEmpty(processRecord.getProcessName())) {
            return new CommonResult().validateFailed("流程类型不能为空");
        }
        if (this.processRecordSerivce.submitbenji(processRecord).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("提交失败");
    }
}